import turtle
import math

screen = turtle.Screen()
screen.setup(width=800, height=800)
screen.bgcolor('white')
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.pensize(2)

def draw_face_core():
    # 精确位置与比例的椭圆脸型
    t.penup(); t.goto(0,-60)
    t.pendown(); t.seth(0)
    t.fillcolor('#ffe0ca')
    t.begin_fill()
    for _ in range(2):
        t.circle(145,90)
        t.circle(145//1.35,90)
    t.end_fill()
    t.penup()
    t.goto(0, 40)

# 画额头及部分碎发（简单描边）
def draw_hair():
    t.pensize(12)
    t.pencolor('black')
    hair_points = [(-85,90), (-100,175), (-55,160), (-115,95),(-90,70), (-60,180), (-20,170), (60,150), (98,110), (67,132), (120,180), (105,80)]
    t.penup()
    for idx, (x,y) in enumerate(hair_points):
        if idx == 0:
            t.goto(x,y)
            t.pendown()
        else:
            t.goto(x,y)
    t.penup()
    t.pensize(2)

# 更符合真人的黑框眼镜
def draw_eyeglasses():
    t.pensize(8)
    for x in [-49, 51]:
        t.penup(); t.goto(x,62)
        t.pendown(); t.setheading(-12)
        t.circle(41, 360)
    # 鼻梁连线
    t.pensize(10)
    t.penup(); t.goto(-12,60); t.pendown(); t.goto(12,60)
    t.pensize(2)

# 真人比例的眼睛、瞳孔、反光（黑眼珠不夸张）
def draw_eyes():
    for x in [-24, 24]:
        # 眼白
        t.penup(); t.goto(x,57); t.pendown(); t.fillcolor('white')
        t.begin_fill(); t.circle(15); t.end_fill()
        # 上眼睑阴影
        t.penup(); t.goto(x-11,70); t.pendown(); t.pencolor('gray')
        t.setheading(-50)
        t.circle(15,40)
        # 瞳孔
        t.penup(); t.goto(x,62); t.pendown(); t.pencolor('black'); t.fillcolor('black')
        t.begin_fill(); t.circle(5); t.end_fill()
        # 反光点
        t.penup(); t.goto(x+3,68); t.pendown(); t.pencolor('white'); t.fillcolor('white')
        t.begin_fill(); t.circle(2); t.end_fill()
    t.pencolor('black')
    t.pensize(2)

# 绘制鼻梁、鼻翼及鼻孔
def draw_nose():
    t.pensize(2)
    t.penup(); t.goto(-5,33); t.pendown(); t.setheading(-100)
    t.pencolor('#c08a60')
    t.circle(15,60)
    t.pensize(1)
    # 鼻孔
    t.penup(); t.goto(-3,21); t.pendown(); t.dot(5,'#793d13')
    t.penup(); t.goto(10,19); t.pendown(); t.dot(4,'#793d13')
    t.pencolor('black')

# 更加贴合照片的嘴巴结构，嘴角有笑感
def draw_mouth():
    t.pensize(3)
    t.penup(); t.goto(-25,9); t.pendown(); t.pencolor('#ba7e60')
    t.setheading(-18)
    t.circle(26,33)
    t.pensize(1)
    # 画唇线
    t.penup(); t.goto(-13,5); t.pendown(); t.pencolor('#914c33')
    t.setheading(-10)
    t.circle(13,26)
    t.pencolor('black')

# 可选添加下巴阴影、脸颊红润，提升立体感
def draw_cheek_highlight():
    t.penup(); t.goto(-38,36); t.pendown()
    t.pencolor('pink'); t.fillcolor('#ffb6c1')
    t.begin_fill(); t.circle(13); t.end_fill()
    t.penup(); t.goto(38,34); t.pendown()
    t.begin_fill(); t.circle(11); t.end_fill()
    t.pencolor('black')

def main():
    draw_face_core()
    draw_hair()
    draw_eyeglasses()
    draw_eyes()
    draw_nose()
    draw_cheek_highlight()
    draw_mouth()
    t.penup(); t.goto(0,-120); t.pencolor('gray')
    t.write('Zhiyang 写实风局部头像 —— 可联系AI调整细节',align='center', font=('Arial', 13, 'normal'))
    t.hideturtle()
    turtle.done()

if __name__ == '__main__':
    main()
